/*
 * Created by Jaren at 2021/11/29 14:44
 */

import 'package:binary/binary.dart';
import 'package:inmotion_protocol/common/mode.dart';
import 'package:inmotion_protocol/lorin/bean/base/vehicle_real_time_info.dart';

/// 车辆数据，如速度，里程等
/// 各类型协议和产品型号根据实际情况补充内容
class VehicleData {
  RealTimeInfo realTimeInfo = UnknownRealTimeInfo.instance;
  RealTimeState realTimeState = UnknownRealTimeState.instance;
  RealTimeError realTimeError = UnknownRealTimeError.instance;

  Settings settings = UnknownSettings.instance;
}

abstract class AllRealTimeData<T1 extends RealTimeInfo, T2 extends RealTimeState, T3 extends RealTimeError> {
  T1 realTimeInfo;

  T2 realTimeState;

  T3 realTimeError;

  AllRealTimeData(this.realTimeInfo, this.realTimeState, this.realTimeError);

  @override
  String toString() {
    return 'AllRealTimeData{realTimeInfo: ${realTimeInfo.toString()}, realTimeState: ${realTimeState.toString()}, realTimeError: ${realTimeError.toString()}';
  }

  int length() {
    return realTimeInfo.length() + realTimeState.length() + realTimeError.length();
  }
}

abstract class VehicleSynthesizeRealTimeInfo<T1 extends CommonVehicleRealTimeInfo, T2 extends RealTimeState, T3 extends RealTimeError> {
  T1 commonVehicleRealTimeInfo;
  T2 realTimeState;
  T3 realTimeError;

  VehicleSynthesizeRealTimeInfo(this.commonVehicleRealTimeInfo, this.realTimeState, this.realTimeError);

  @override
  String toString() {
    return 'VehicleSynthesizeRealTimeInfo{vehicleRealTimeInfo: ${commonVehicleRealTimeInfo.toString()}, realTimeState: ${realTimeState.toString()}, realTimeError: ${realTimeError.toString()}';
  }

  int length() {
    return commonVehicleRealTimeInfo.length() + realTimeState.length() + realTimeError.length();
  }
}

abstract class VehicleRealTimeInfo {

  int length();

}

abstract class RealTimeInfo {
  Int16 voltage = Int16.zero;
  Int16 current = Int16.zero;
  Int16 speed = Int16.zero;
  Uint16 mileage = Uint16.zero;
  Uint16 batteryLevel = Uint16.zero;

  int length();
}

abstract class RealTimeState {
  Mode pcMode = Mode.idle;
  Uint32 pcModeValue = Uint32.zero;
  Uint4 headlightState = Uint4.zero;
  Uint4 lockState = Uint4.zero;

  int length();
}

abstract class RealTimeError {
  int length();
}

abstract class HistoryStatistics {
  int length();
}

abstract class TotalStatistics {
  int length();
}

abstract class BatteryRealTimeInfo {
  int length();
}

abstract class Settings {
  int length();
}

abstract class AbsBMSLog {}

class UnknownRealTimeInfo extends RealTimeInfo {
  static final instance = UnknownRealTimeInfo();

  @override
  int length() {
    throw UnimplementedError();
  }
}

class UnknownRealTimeState extends RealTimeState {
  static final instance = UnknownRealTimeState();

  @override
  int length() {
    throw UnimplementedError();
  }
}

class UnknownRealTimeError extends RealTimeError {
  static final instance = UnknownRealTimeError();

  @override
  int length() {
    throw UnimplementedError();
  }
}

class UnknownSettings extends Settings {
  static final instance = UnknownSettings();

  @override
  int length() {
    throw UnimplementedError();
  }
}

class UnknownVehicleData extends VehicleData {
  static final instance = UnknownVehicleData();
}
